/*
 * Adaptable.java
 *
 * Created Oct 10, 2006
 * David Connell
 * Copyright (c) 2005 Synergy Systems, Inc
 */
package org.puresilk.afx.adaptable;

import java.util.logging.Logger;
import org.jdom.Element;
import org.jdom.transform.XSLTransformException;

import org.puresilk.afx.interfaces.SilkXMLBean;

/**
 * Generic base class for Adaptable beans. Default
 * implementation defines the wrapper api for XML
 * adaptable beans.  
 */
public class Adaptable implements SilkXMLBean {
	private SilkXMLBean bean = null;
	private static Logger logger = Logger.getLogger(Adaptable.class.getName());
	
	/** default constructor */
	public Adaptable(){}
		
	/** self loading constructor */
	public Adaptable(SilkXMLBean bean){
		setBean(bean);
	}
	
	/** bean loader */
	public void setBean(SilkXMLBean bean){
		this.bean = bean;   
	}
	
	/** bean extractor */
	public SilkXMLBean getBean() {
		return bean;
	}

	/* (non-Javadoc)
	 * @see com.rlsworx.beans.XMLBean#from_xml(org.jdom.Element)
	 */
	public void from_xml(Element xml) {
		try{
			if (bean != null)
				bean.from_xml(xml);
		}
		catch(XSLTransformException ex){
			logger.throwing("Adaptable", "from_xml", ex);
		}
	}

	/* (non-Javadoc)
	 * @see com.rlsworx.beans.XMLBean#to_xml()
	 */
	public Element to_xml() {
		Element xml = null;
		if(bean != null)
			xml = bean.to_xml();
		return xml;
	}	
	
	/** Delegates to to_xml() */
	public Element to_xmlNode() { return to_xml(); }
}
